package cn.com.winson.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import cn.com.winson.dao.UserMapper;
import cn.com.winson.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper userMapper;
	
	/* 注入Redis操作模板 */
	@Autowired
	private RedisTemplate<String, String> redisTemplate;

	@Override
	public String getUserById(String id) {
		String userInfo = redisTemplate.opsForValue().get("userInfo");
		if (null == userInfo) {
			String userStr = userMapper.selectByPrimaryKey(id).toString();
			redisTemplate.opsForValue().set("userInfo", userStr);
			return userStr;
		}
		return userInfo;
	}

}
